export function transListToTreeData(arr) {
  const parent = arr.filter(item => !item.p_id)

  parent.forEach(item1 => {
    item1.children = arr.filter(item2 => item1.id === item2.p_id)
  })

  return parent
}

export function toInt(val) {
  val = Number.parseInt(val)
  if (Number.isNaN(val)) {
    return undefined
  } else {
    return val
  }
}

export function priceToInt(val) {
  if (val === '') {
    return undefined
  }
  const number = Number.parseInt(val * 100)
  if (Number.isNaN(number)) {
    return undefined
  } else {
    return number
  }
}

export function initToPrice(val) {
  if (typeof val !== 'number' || Number.isNaN(val)) {
    return undefined
  } else {
    return (val / 100).toFixed(2)
  }
}
